package lesson11;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class Demo_1102 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println(" 线程安全的list");
        List<Integer> list=new CopyOnWriteArrayList<>(new ArrayList<>());
        list.add(1);
        System.out.println(list);
        CountDownLatch countDownLatch=new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            System.out.println("预备");
            Thread thread = new Thread(() -> {
                try {
                    System.out.println("开炮");
                    TimeUnit.SECONDS.sleep(2);
                    System.out.println("到达");
                    countDownLatch.countDown();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"palyer"+i);
            thread.start();

        }
        countDownLatch.await();
        System.out.println("颁奖");

    }
}
